package org.rvk.vms.service.department;

import java.util.List;

import org.rvk.vms.api.department.IDepartmentService;
import org.rvk.vms.dal.dao.DepartmentDao;
import org.rvk.vms.dal.dao.GenericDao;
import org.rvk.vms.dal.entities.Department;
import org.rvk.vms.dal.entities.Role;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
/**
 * 
 * @author Ashish Kumar Sinha <aksinha.mail@gmail.com>
 *
 */
@Service("departmentService")
@Scope((BeanDefinition.SCOPE_SINGLETON))
public class DepartmentService implements IDepartmentService {

	@Autowired
	private GenericDao genericDao;
	
	@Autowired
	private DepartmentDao departmentDao;

	@Override
	public void addDepartment(Department newDepartment) {
		if(newDepartment == null){
			throw new IllegalArgumentException("Department to be added is null");
		}
		genericDao.create(newDepartment);
	}

	@Override
	public void removeDepartment(String departmentId) {
		if(departmentId == null){
			throw new IllegalArgumentException("DepartmentId is null");
		}
		Department department = genericDao.findById(Department.class, departmentId);
		if(department == null){
			throw new IllegalArgumentException("Department with Id:" + departmentId + " doesn't exist");
		}
		genericDao.delete(department);
	}

	@Override
	public void updateDepartment(Department department) {
		if(department == null){
			throw new IllegalArgumentException("Department to be updated is null");
		}
		genericDao.createOrUpdate(department);
	}

	@Override
	public Department getDepartmentWithId(String departmentId) {
		if(departmentId == null){
			throw new IllegalArgumentException("DepartmentId is null");
		}
		Department department = genericDao.findById(Department.class, departmentId);
		return department;
	}

	@Override
	public List<Department> getAllDepartments() {
		return departmentDao.getAllDepartments();
	}

	@Override
	public List<Role> getRoless(String deptartmentCode) {
		return null;
	}

}
